package com.ww.springboot.boot.util;

import com.google.common.util.concurrent.RateLimiter;

import java.util.concurrent.TimeUnit;

/**
 * 描述：
 * 令牌桶--可以预取1个令牌 允许突发
 * 漏桶--保持匀速输出
 *
 *
 * @author wanwei
 * @since 2021-10-22 09:23
 */
public class RateLimiterDemo {

    static RateLimiter rateLimiter = RateLimiter.create(2);
    static RateLimiter rateLimiter2 = RateLimiter.create(2,3L, TimeUnit.SECONDS);


    public static void main(String[] args) throws InterruptedException {

        while(true){
            System.out.println(rateLimiter2.acquire(1));
        }

    }
}
